package van.planifolia.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;
import java.util.*;

/**
 * Created by Intellij IDEA<br>
 * 用来进行页面间路由的Controller
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/11/18 17:59
 */
@Controller
public class PageController {
    /**
     * 用来跳转到主页的Controller
     * @param model 存放数据的中间类
     * @return index.html
     */
    @RequestMapping("/Index")
    public String index(Model model){
        // 存放到model中的数据可以直接使用thymeleaf取到
        model.addAttribute("msg","你好世界！");
        model.addAttribute("str","hello world");
        model.addAttribute("date", new Date(2022, Calendar.DECEMBER,18));
        List<String> strings = new ArrayList<>();
        strings.add("漳州");
        strings.add("豫州");
        strings.add("荆州");
        Map<String,List<String>> address = new HashMap<>();
        address.put("地区",strings);
        model.addAttribute("address",address);
        // 要跳转到的页面
        return "index";
    }

    /**
     * 接受前端请求的controller
     * @param msg1 消息1
     * @param msg2 消息2
     * @return 消息输出到网页
     */
    @RequestMapping("/show")
    @ResponseBody
    public String show(String msg1,String msg2){
        return msg1+","+msg2;
    }
    /**
     * 接受前端请求的controller
     * @param msg1 消息1
     * @param msg2 消息2
     * @return 消息输出到网页
     */
    @RequestMapping("/showsp/{msg1}/{msg2}")
    @ResponseBody
    public String showSp(@PathVariable String msg1, @PathVariable String msg2){
        return msg1+","+msg2;
    }
}
